// subpage/pages/combo/combo.js
const app = getApp();
import service from '../../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    baseUrl: app.data.url,
    comboList:[],
    tab: [{id: 0, name: '购买套餐'}, {id: 1, name: '我的套餐'}],
    current: 1,
    myComboList: [],
    gunId: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.gunId){
      this.setData({
        gunId: options.gunId
      })
    }
    this.getList()
    this.myCombo()
  },
  gocombo(){
    this.setData({
      current: 0
    })
  },
  getList (){
    let that = this
    let res = service('GET', '/personal/combo/activity/all').then(result => {
      console.log('套餐',result)
      that.setData({
        comboList: result.data.list,
      })
    })
  },
  //购买
  detail(event){
    console.log('点击购买',event)
    wx.navigateTo({
      url: '/package1/pages/combo/info?id='+event.currentTarget.dataset.id+'&gunId='+this.data.gunId,
    })
    return
    let id = event.target.dataset.id
    let that = this
    let res = service('POST', '/combo/activity/buy',{
      id: id,
      force: false
    }).then(result => {
      console.log('套餐',result)
      if(result.data.code ==0){
        wx.showToast({
          title: '购买成功',
          icon: 'none'
        })
      }
      // that.setData({
      //   comboList: result.data.list,
      // })
    })
  },
  changeTab(e){
    console.log('e', e)
    this.setData({
      current: e.detail.current
    })
  },
  clickTab(e){
    this.setData({
      current: e.target.dataset.current
    })

  },

  //我的套餐
  myCombo(){
    let that = this
    let res = service('POST', '/personal/combo/my',{gunId: this.data.gunId}).then(result => {
      console.log('我的套餐',result.data)
      // result.data.list.map( item => {
      // })
      that.setData({
        myComboList: result.data.page.list
      })
     
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})